/**
 * 菜单框架
 */
class FrameMenu extends egret.DisplayObjectContainer {
    /** 加载菜单栏 */
    private menu_png: egret.Bitmap = Main.createBitmapByName("menu_1_png");
    /** 按钮公共y轴位置 */
    private btnYPath = 10;
    /** 加载提示 */
    private tip_png: egret.Bitmap = Main.createBitmapByName("tip_1_png");
    /** BGM开关 */
    private sound_btn: Boolean = true;

    /** 缩放模式 */
    private scaleModule = true;

    public constructor() {
        super();
        this.once(egret.Event.ADDED_TO_STAGE, this.init, this);
    }

    private init() {
        /** 加载菜单栏 */
        this.addChild(this.menu_png);
        /** MENU按钮设置 */
        this.menuBtnSetting();
        /** BGM开关设置 */
        this.soundBtnSettin();
        /** TIP按钮设置 */
        // this.tipBtnSetting();
        /** TIP道具设置 */
        this.tipItemSetting();
    }
    /** menu设置 */
    public menuSetting(num) {
        this.menu_png.texture = RES.getRes(`menu_${num}_png`);
        this.tip_png.texture = RES.getRes(`tip_${num}_png`);
        this.menu_png.anchorOffsetX = this.menu_png.width;
        this.menu_png.x = this.stage.stageWidth;
    }
    /** BGM开关设置 */
    private soundBtnSettin() {
        const sound_png: egret.Bitmap = Main.createBitmapByName("sound_open_png");
        this.addChild(sound_png);
        sound_png.x = 900;
        sound_png.y = this.btnYPath;
        Main.dragGetPatn(sound_png, this, { startFun: soundBtnHandler }, false);
        /** BGM开关点击处理 */
        function soundBtnHandler(target, container) {
            container.sound_btn = !container.sound_btn;
            if (container.sound_btn) {
                console.log("开启BGM");
                target.texture = RES.getRes("sound_open_png");
                StartScreen.mviaBgm = StartScreen.bgm.play();
            } else {
                console.log("关闭BGM");
                target.texture = RES.getRes("sound_close_png");
                StartScreen.mviaBgm.stop();
            }
        }
    }
    /** TIP按钮设置 */
    private tipBtnSetting() {
        const tip_open_png: egret.Bitmap = Main.createBitmapByName("tip_open_png");
        this.addChild(tip_open_png);
        tip_open_png.x = 910 + 90// 1000 + 90;
        tip_open_png.y = this.btnYPath;
        Main.dragGetPatn(tip_open_png, this, { startFun: tipBtnHandler }, false);
        /** TIP按钮点击处理 */
        function tipBtnHandler(target, container) {
            console.log("弹出提示");
            egret.Tween.get(container.tip_png)
                .to({ alpha: 1, scaleY: 1 }, 200)
                .wait(1000)
                .to({ alpha: 0 }, 200)
                .to({ scaleY: 0 });
        }
    }
    /** TIP道具设置 */
    private tipItemSetting() {
        this.addChild(this.tip_png);
        this.tip_png.x = 540;
        this.tip_png.y = 75;
        this.tip_png.alpha = 0;
        this.tip_png.scaleY = 0;
    }
    /** MENU按钮设置 */
    private menuBtnSetting() {
        const menu_open_png: egret.Bitmap = Main.createBitmapByName("menu_open_png");
        this.addChild(menu_open_png);
        menu_open_png.x = 1000;
        menu_open_png.y = this.btnYPath;
        Main.dragGetPatn(menu_open_png, this, { startFun: menuBtnHandler }, false);
        /** MENU开关点击处理 */
        function menuBtnHandler(target, container) {
            // console.log("弹出菜单");
            container.scaleModule = !container.scaleModule;
            if (container.scaleModule) {
                console.log("showAll");
                container.stage.scaleMode = egret.StageScaleMode.SHOW_ALL;
            } else {
                console.log("noBorder");
                container.stage.scaleMode = egret.StageScaleMode.NO_BORDER;
            }
        }
    }
}